package thread;

//单例模式--饿汉模式
// 饿 是尽早创建实例
class Singleton{
    private static Singleton instance=new Singleton();//类加载的时候触发
    public static Singleton getInstance(){
        return instance;
    }
    private Singleton(){

    }
}
public class Demo25 {
    public static void main(String[] args) {
        Singleton t1=Singleton.getInstance();
        Singleton t2=Singleton.getInstance();
        System.out.println(t1==t2);//true
        //Singleton t3=new Singleton();//报错
    }
}
